var socket;
var deviceCount = 0;
if(typeof(WebSocket) == "undefined") {
}else{
    var wsUrl = "wss://"+ window.location.host+"/antifake/websocket/3,"+$("#factoryIds").val();
    socket = new WebSocket(wsUrl);
    //打开事件
    socket.onopen = function() {
        console.log("Socket 已打开");
    };
    //获得消息事件
    socket.onmessage = function(msg) {
        var myobj=eval(msg.data);
        $("#vvv").empty();
        for(var i=0;i<myobj.length;i++){
            var tb = document.getElementById("vvv");
            var tr = tb.insertRow(0);
            tr.style.cssText = tb.rows[0].style.cssText;
            var td1 = tr.insertCell();
            var td2 = tr.insertCell();
            var td3 = tr.insertCell();
            td1.innerHTML =myobj[i].factoryName+"("+myobj[i].deviceId+")";
            td2.innerHTML = myobj[i].successNum;
            td3.innerHTML = myobj[i].failNum;
        }
        if(deviceCount != myobj.length){
            $("#btns").click();
            deviceCount = myobj.length;
            $("#deviceCount").html(deviceCount);
        }
    };
    //关闭事件
    socket.onclose = function() {
        console.log("Socket已关闭");
    };
    //发生了错误事件
    socket.onerror = function() {
        alert("Socket发生了错误");
        //此时可以尝试刷新页面
    }
}